const express = require('express');
const router = express.Router();
const sqlFn = require('../mysql');

/**
 * @swagger
 * tags:
 *   name: Test
 *   description: 测试接口
 */

/**
 * @swagger
 * /test:
 *   get:
 *     summary: 获取测试数据
 *     description: 返回所有测试数据项。
 *     tags: [Test]
 *     responses:
 *       200:
 *         description: 成功返回测试数据列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: string
 *                   example: '0000'
 *                 record:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: integer
 *                         example: 1
 *                       name:
 *                         type: string
 *                         example: "测试数据名称"
 */
router.get('', (req, res, next) => {
    const sql = "select * from tset";
    sqlFn(sql, [], (err, data) => {
        if (err) {
            next(err);
            return;
        }
        res.send({ code: 200, record: data });
    });
});

module.exports = router;
